We generated a heat map using the Leaflet library to visualize the geographical distribution of rat sightings based on latitude and longitude.
top = 40.917577 # north lat
left = -74.259090 # west long
right = -73.700272 # east long
bottom = 40.477399 # south lat
nyc = rats_raw %>%
filter(latitude >= bottom) %>%
filter ( latitude <= top) %>%
filter( longitude >= left ) %>%
filter(longitude <= right)
center_lon = median(nyc$longitude,na.rm = TRUE)
center_lat = median(nyc$latitude,na.rm = TRUE)
count = nyc %>%
group_by(location) %>%
count()
nyc = merge(nyc, count, by = "location")
factpal = colorFactor("blue", nyc$n)
nyc %>%
leaflet() %>%
addProviderTiles("Esri.NatGeoWorldMap") %>%
addHeatmap(lng = ~longitude, lat = ~latitude, intensity = ~(nyc$n), blur = 20, max = 0.05, radius = 15) %>%
setView(lng=center_lon, lat=center_lat,zoom = 10)
In summary, the heat map visualizes the density of occurrences of rat sightings within NYC. Warmer colors indicate higher density, while cooler colors represent lower density.
overall <- rats_raw %>%
group_by(sighting_year, sighting_month_num, sighting_day) %>%
summarize(count = n()) %>%
mutate(date = as.Date(paste(sighting_year, sighting_month_num, sighting_day, sep = "-")))
time_series = xts(overall$count , order.by= overall$date)
hchart(time_series, name = "Rat Sightings") %>%
hc_add_theme(hc_theme_darkunica()) %>%
hc_credits(enabled = TRUE, text = "Sources: City of New York", style = list(fontSize = "12px")) %>%
hc_title(text = "Time Series of NYC Rat Sightings") %>%
hc_legend(enabled = TRUE)
The time series plot visually represents the trend and pattern of rat sightings in New York City over time. The x-axis represents the timeline, and the y-axis represents the count of rat sightings on each corresponding date.